package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderDetailMapper {
    void insertBatch(List<OrderDetail> orderDetailList);

    @Select("select * from order_detail where order_id = #{orderId}")
    List<OrderDetail> selectByOrderId(Long orderId);

    @Select("select od.name name, sum(od.number) number from order_detail od, orders o " +
            "where od.order_id = o.id and o.status = 5 " +
            "and order_time >= #{beginTime} " +
            "and order_time <= #{endTime} " +
            "group by name " +
            "order by number desc " +
            "limit 10")
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
